package applications.libraryForm.ui.lib;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.util.Observable;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SpringLayout;
import javax.swing.SwingConstants;

import ontocompo.lib.SpringUtilities;

import org.objectweb.fractal.fraclet.annotations.Component;
import org.objectweb.fractal.fraclet.annotations.Interface;
import org.objectweb.fractal.fraclet.annotations.Requires;

import applications.libraryForm.fc.api.LibraryForm;
import applications.studentApplicationForm.fc.api.StudentForm;

@Component(provides = {@Interface(name = "jPanelItf", signature = org.objectweb.fractal.swing.JPanelItf.class),@Interface(name = "observer", signature = java.util.Observer.class), @Interface(name = "jPanelAttributes", signature = org.objectweb.fractal.swing.JPanelAttributes.class), @Interface(name = "uicontainerservice", signature = ontocompo.api.UIContainerService.class), @Interface(name = "ontocompointrospection", signature = ontocompo.api.OntoCompoIntrospection.class)})


public class LibraryFormStudentPersonalDataButton extends JPanel implements java.util.Observer, org.objectweb.fractal.swing.JPanelItf, org.objectweb.fractal.swing.JPanelAttributes, ontocompo.api.UIContainerService, ontocompo.api.OntoCompoIntrospection {


	private String uid;
	private org.objectweb.fractal.api.Component c;

	@Requires(name = "libraryFormFamilyNameLabel")
	private ontocompo.api.UIContainerService libraryFormFamilyNameLabel;

	@Requires(name = "libraryFormFamilyNameValue")
	private ontocompo.api.UIContainerService libraryFormFamilyNameValue;


	@Requires(name = "libraryFormFirstNameLabel")
	private ontocompo.api.UIContainerService libraryFormFirstNameLabel;

	@Requires(name = "libraryFormFirstNameValue")
	private ontocompo.api.UIContainerService libraryFormFirstNameValue;


	@Requires(name = "libraryFormDateOfBirthLabel")
	private ontocompo.api.UIContainerService libraryFormDateOfBirthLabel;

	@Requires(name = "libraryFormDateOfBirthValue")
	private ontocompo.api.UIContainerService libraryFormDateOfBirthValue;


	@Requires(name = "libraryFormStudentStatusLabel")
	private ontocompo.api.UIContainerService libraryFormStudentStatusLabel;

	@Requires(name = "libraryFormStudentStatusValue")
	private ontocompo.api.UIContainerService libraryFormStudentStatusValue;


	@Requires(name = "libraryFormExpiryDateLabel")
	private ontocompo.api.UIContainerService libraryFormExpiryDateLabel;

	@Requires(name = "libraryFormExpiryDateValue")
	private ontocompo.api.UIContainerService libraryFormExpiryDateValue;



	@Requires(name = "libraryFormStudentNumberLabel")
	private ontocompo.api.UIContainerService libraryFormStudentNumberLabel;

	@Requires(name = "libraryFormStudentNumberValue")
	private ontocompo.api.UIContainerService libraryFormStudentNumberValue;



	@Requires(name = "libraryFormAddressLabel")
	private ontocompo.api.UIContainerService libraryFormAddressLabel;

	@Requires(name = "libraryFormAddressValue")
	private ontocompo.api.UIContainerService libraryFormAddressValue;


	@Requires(name = "libraryFormZipCodeLabel")
	private ontocompo.api.UIContainerService libraryFormZipCodeLabel;

	@Requires(name = "libraryFormZipCodeValue")
	private ontocompo.api.UIContainerService libraryFormZipCodeValue;



	@Requires(name = "libraryFormCountryLabel")
	private ontocompo.api.UIContainerService libraryFormCountryLabel;

	@Requires(name = "libraryFormCountryValue")
	private ontocompo.api.UIContainerService libraryFormCountryValue;


	@Requires(name = "libraryFormTelephoneLabel")
	private ontocompo.api.UIContainerService libraryFormTelephoneLabel;

	@Requires(name = "libraryFormTelephoneValue")
	private ontocompo.api.UIContainerService libraryFormTelephoneValue;





	@Requires(name = "libraryformdirectoryservice")
	private applications.libraryForm.fc.api.LibraryFormDirectoryService libraryformdirectoryservice;

	@Requires(name = "libraryformdirectoryobservable")
	private ontocompo.api.Observable libraryformdirectoryobservable;



	public LibraryFormStudentPersonalDataButton() {
		super();
		this.uid = "applications.libraryForm.ui.lib.LibraryFormStudentPersonalDataButton";
		System.out.println(this.toString() + "created");

	}

	@Override
	public void init() {

		// TODO Auto-generated method stub

		this.libraryformdirectoryobservable.addObserver(this);

		this.setBackground(Color.white);

		this.libraryFormFamilyNameLabel.init();
		this.libraryFormFamilyNameValue.init();


		this.libraryFormFirstNameLabel.init();
		this.libraryFormFirstNameValue.init();

		this.libraryFormDateOfBirthLabel.init();
		this.libraryFormDateOfBirthValue.init();

		this.libraryFormStudentStatusLabel.init();
		this.libraryFormStudentStatusValue.init();

		this.libraryFormExpiryDateLabel.init();
		this.libraryFormExpiryDateValue.init();

		this.libraryFormStudentNumberLabel.init();
		this.libraryFormStudentNumberValue.init();

		this.libraryFormAddressLabel.init();
		this.libraryFormAddressValue.init();


		this.libraryFormZipCodeLabel.init();
		this.libraryFormZipCodeValue.init();


		this.libraryFormCountryLabel.init();
		this.libraryFormCountryValue.init();


		this.libraryFormTelephoneLabel.init();
		this.libraryFormTelephoneValue.init();




		JPanel panel = new JPanel(new GridLayout(10,2,20,20));
		panel.setBackground(Color.white);

		panel.add(this.libraryFormFamilyNameLabel.getComponentItSelf());
		panel.add(this.libraryFormFamilyNameValue.getComponentItSelf());


		panel.add(libraryFormFirstNameLabel.getComponentItSelf());
		panel.add(libraryFormFirstNameValue.getComponentItSelf());

		panel.add(libraryFormDateOfBirthLabel.getComponentItSelf());
		panel.add(libraryFormDateOfBirthValue.getComponentItSelf());

		panel.add(libraryFormStudentStatusLabel.getComponentItSelf());
		panel.add(libraryFormStudentStatusValue.getComponentItSelf());

		panel.add(libraryFormExpiryDateLabel.getComponentItSelf());
		panel.add(libraryFormExpiryDateValue.getComponentItSelf());

		panel.add(libraryFormStudentNumberLabel.getComponentItSelf());
		panel.add(libraryFormStudentNumberValue.getComponentItSelf());

		panel.add(libraryFormAddressLabel.getComponentItSelf());
		panel.add(libraryFormAddressValue.getComponentItSelf());


		panel.add(libraryFormZipCodeLabel.getComponentItSelf());
		panel.add(libraryFormZipCodeValue.getComponentItSelf());


		panel.add(libraryFormCountryLabel.getComponentItSelf());
		panel.add(libraryFormCountryValue.getComponentItSelf());


		panel.add(libraryFormTelephoneLabel.getComponentItSelf());
		panel.add(libraryFormTelephoneValue.getComponentItSelf());


		this.add(panel, BorderLayout.WEST);




	}

	protected JLabel createTd(String txt)
	{
		JLabel result = new JLabel(txt);
		result.setFont(result.getFont().deriveFont(Font.PLAIN));
		result.setHorizontalAlignment(SwingConstants.LEFT);

		return result;
	}

	protected JPanel createBox(int thickness)
	{
		JPanel result = new JPanel();
		if (thickness > 0) result.setBorder(BorderFactory.createLineBorder(Color.black, thickness));
		result.setBackground(Color.white);
		return result;
	}


	private JLabel createTh(String string) {
		// TODO Auto-generated method stub
		JLabel result = new JLabel(string);
		// result.setBorder(BorderFactory.createLineBorder(Color.blue, 1));

		result.setHorizontalAlignment(SwingConstants.CENTER);
		return result;
	}


	@Override
	public JComponent getComponentItSelf() {
		// TODO Auto-generated method stub
		return this;
	}

	@Override
	public void update(Object o) {

		// TODO Auto-generated method stub
		LibraryForm library = this.libraryformdirectoryservice.getLibraryForm();

		this.removeAll();
		this.setBackground(Color.white);

		JPanel panel = new JPanel(new GridLayout(10,2,20,20));
		panel.setBackground(Color.white);



		if (library != null)
		{
			this.setBackground(Color.white);
			this.removeAll();

			this.libraryFormFamilyNameValue.update(library.getFamilyName());
			this.libraryFormFirstNameValue.update(library.getFirstName());

			this.libraryFormDateOfBirthValue.update(library.getDateOfBirth());
			this.libraryFormStudentStatusValue.update(library.getStudentStatus());

			this.libraryFormExpiryDateValue.update(library.getExpiryDate());
			this.libraryFormStudentNumberValue.update(library.getStudentNumber());

			this.libraryFormAddressValue.update(library.getAddress().getAdress());
			this.libraryFormZipCodeValue.update(library.getAddress().getZipCode());

			this.libraryFormCountryValue.update(library.getAddress().getCountry());
			this.libraryFormTelephoneValue.update(library.getAddress().getTelephone());

			
			panel.add(this.libraryFormFamilyNameLabel.getComponentItSelf());
			panel.add(this.libraryFormFamilyNameValue.getComponentItSelf());
			panel.add(libraryFormFirstNameLabel.getComponentItSelf());
			panel.add(libraryFormFirstNameValue.getComponentItSelf());

			panel.add(libraryFormDateOfBirthLabel.getComponentItSelf());
			panel.add(libraryFormDateOfBirthValue.getComponentItSelf());

			panel.add(libraryFormStudentStatusLabel.getComponentItSelf());
			panel.add(libraryFormStudentStatusValue.getComponentItSelf());

			panel.add(libraryFormExpiryDateLabel.getComponentItSelf());
			panel.add(libraryFormExpiryDateValue.getComponentItSelf());

			panel.add(libraryFormStudentNumberLabel.getComponentItSelf());
			panel.add(libraryFormStudentNumberValue.getComponentItSelf());

			panel.add(libraryFormAddressLabel.getComponentItSelf());
			panel.add(libraryFormAddressValue.getComponentItSelf());


			panel.add(libraryFormZipCodeLabel.getComponentItSelf());
			panel.add(libraryFormZipCodeValue.getComponentItSelf());


			panel.add(libraryFormCountryLabel.getComponentItSelf());
			panel.add(libraryFormCountryValue.getComponentItSelf());


			panel.add(libraryFormTelephoneLabel.getComponentItSelf());
			panel.add(libraryFormTelephoneValue.getComponentItSelf());

			this.add(panel, BorderLayout.WEST);	

			this.getParent().validate();  // pour rafraichir la page



		}
		
		


		



	}

	public String toString() {
		return "LibraryFormStudentPersonalDataButton";
	}


	@Override
	public org.objectweb.fractal.api.Component getFractalComponent() {
		// TODO Auto-generated method stub
		return this.c;
	}

	@Override
	public String getUid() {
		// TODO Auto-generated method stub
		return this.uid;
	}

	@Override
	public void setFractalComponent(org.objectweb.fractal.api.Component c) {
		// TODO Auto-generated method stub
		this.c = c;

	}

	@Override
	public void setUid(String uid) {
		// TODO Auto-generated method stub
		this.uid = uid;
	}

	@Override
	public void update(Observable o, Object arg) {
		// TODO Auto-generated method stub

		LibraryForm bkk = this.libraryformdirectoryservice.getLibraryForm();

		if (bkk == null){
			return;
		}
		else { 
			this.update(bkk);
		}

	}



}
